package com.google.careerexplorernative;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import java.util.ArrayList;

/**
 * A fragment to implement the explore tab.
 */
public class ExploreFragment extends Fragment implements View.OnClickListener{
    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    private static final String ARG_SECTION_NUMBER = "section_number";

    private View rootView;
    private Button alphabeticalButton;
    private Button occupationButton;
    private Button interestsButton;
    private Button highestPayingButton;
    private Button fastestGrowingButton;
    private Button newJobsButton;

    private Button backButton;

    private ArrayList<Button> topLevelButtonList = new ArrayList<Button>();
    /**
     * Returns a new instance of this fragment for the given section
     * number.
     */
    public static ExploreFragment newInstance(int sectionNumber) {
        ExploreFragment fragment = new ExploreFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);
        fragment.setArguments(args);
        return fragment;
    }

    public ExploreFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_explore, container, false);

        alphabeticalButton = (Button) rootView.findViewById(R.id.alphabetical_button);
        alphabeticalButton.setOnClickListener(this);
        topLevelButtonList.add(alphabeticalButton);
        occupationButton = (Button) rootView.findViewById(R.id.occupation_button);
        occupationButton.setOnClickListener(this);
        topLevelButtonList.add(occupationButton);
        interestsButton = (Button) rootView.findViewById(R.id.interests_button);
        interestsButton.setOnClickListener(this);
        topLevelButtonList.add(interestsButton);
        highestPayingButton = (Button) rootView.findViewById(R.id.highest_paying_button);
        highestPayingButton.setOnClickListener(this);
        topLevelButtonList.add(highestPayingButton);
        fastestGrowingButton = (Button) rootView.findViewById(R.id.fastest_growing_button);
        fastestGrowingButton.setOnClickListener(this);
        topLevelButtonList.add(fastestGrowingButton);
        newJobsButton = (Button) rootView.findViewById(R.id.most_new_openings_button);
        newJobsButton.setOnClickListener(this);
        topLevelButtonList.add(newJobsButton);

        backButton = (Button) rootView.findViewById(R.id.back_button);
        backButton.setOnClickListener(this);

        return rootView;
    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.back_button:
                showTopLevelButtons();
                break;
            default:
                hideTopLevelButtons();
        }
    }

    private void hideTopLevelButtons() {
      for(Button button : topLevelButtonList) {
          button.setVisibility(View.GONE);
      }
      backButton.setVisibility(View.VISIBLE);
    }

    private void showTopLevelButtons() {
        for(Button button : topLevelButtonList) {
            button.setVisibility(View.VISIBLE);
        }
        backButton.setVisibility(View.GONE);

    }
}
